/*
 * 版权所有 (C) 2015 知启蒙(ZHIQIM) 保留所有权利。[遇见知启蒙，邂逅框架梦]
 * 
 * https://zhiqim.org/project/zhiqim_framework/zhiqim_httpd.htm
 *
 * Zhiqim Httpd is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */
package org.zhiqim.httpd.util;

import org.zhiqim.httpd.HttpRequest;
import org.zhiqim.httpd.HttpSession;
import org.zhiqim.httpd.HttpSessionUser;
import org.zhiqim.httpd.context.service.VcodeService;

import org.zhiqim.kernel.annotation.AnAlias;
import org.zhiqim.kernel.paging.PageResult;

/**
 * 对HttpSession进行一级封装，实现相关的数据提取工具类，分隔HttpSession代码
 * 
 * @version v1.0.0 @author zouzhigang 2014-3-21 新建与整理
 */
@AnAlias("Sessions")
public class Sessions
{

    /*************************************************************************/
    //获取会话中的特定值，和删除指定的会话
    /*************************************************************************/
    
    /**
     * 获取session中的验证码
     * 
     * @param request 请求
     * @return String 验证码值
     */
    public static String getSessionVerificationCode(HttpRequest request)
    {
        return request.getSessionAttributeString(VcodeService.ZC_VCODE_SESSION_NAME);
    }
    
    /**
     * 获取session中的用户对象列表
     * 
     * @param request 请求
     * @return User子类
     */
    public static PageResult<HttpSessionUser> getSessionUserPage(HttpRequest request, int pageNo, int pageSize)
    {
        return request.getContext().getSessionManager().getSessionUserPage(pageNo, pageSize);
    }

    /**
     * 获取session中的用户对象
     * 
     * @param request 请求
     * @return User子类
     */
    public static HttpSessionUser getSessionUser(HttpRequest request, String sessionId)
    {
        HttpSession session = request.getContext().getSessionManager().getSession(sessionId);
        return session == null?null:session.getSessionUser();
    }
    
    /**
     * 删除session中的指定的用户对象
     * 
     * @param request 请求
     * @param sessionId 会话编号
     */
    public static void removeSession(HttpRequest request, String sessionId)
    {
        request.getContext().getSessionManager().invalidateSession(sessionId);
    }
}
